﻿@model PortalWeb.Models.Cms.ProductViewModel

@{
    ViewBag.Title = "Create";
}

@section scripts{
    <script type="text/javascript" src="~/Scripts/kindeditor-4.1.10/kindeditor-min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        //编辑框
        KindEditor.ready(function (K) {
            window.editor = K.create('#Content', {
                height: '500px',
                uploadJson: '@Url.Action("Upload", "Attachment")',
                fileManagerJson: '@Url.Action("FileManagerJson", "Attachment")',
                allowFileManager: true,
                formatUploadUrl: false
            });
        //首页图片
            var editor2 = K.editor({
                fileManagerJson: '@Url.Action("FileManagerJson", "Attachment")'
            });
            K('#btn_picselect').click(function () {
                editor2.loadPlugin('filemanager', function () {
                    editor2.plugin.filemanagerDialog({
                        viewType: 'VIEW',
                        dirName: 'image',
                        clickFn: function (url, title) {
                            var url;
                            $.ajax({
                                type: "post",
                                url: "@Url.Action("CreateThumbnail", "Attachment")",
                                data: { originalPicture: url },
                                async: false,
                                success: function (data) {
                                    if (data == null) alert("生成缩略图失败！");
                                    else {
                                        K('#DefaultPicUrl').val(data);
                                        K('#imgpreview').attr("src", data);
                                    }
                                    editor2.hideDialog();
                                }
                            });
                        }
                    });
                });
            });
        });

    </script>
}

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">

        @Html.ValidationSummary(true)
        <div class="form-group">
            <label class="control-label col-sm-2" for="CategoryId">产品类别</label>
            <div class="col-sm-10">
                <input id="CategoryId" name="CategoryId" data-options="url:'@Url.Action("JsonTree", "Category", new { model="Article" })'" class="easyui-combotree" style="height: 34px; width: 280px;" />
                @Html.ValidationMessageFor(model => model.CategoryId)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Title, new { @class = "control-label col-sm-2" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.Title, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Title)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Brand, new { @class = "control-label col-sm-2" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.Brand, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Brand)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Price, new { @class = "control-label col-sm-2" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.Price, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Price)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Intro, new { @class = "control-label col-sm-2" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.Intro, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Intro)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(model => model.Content, new { @class = "control-label col-sm-2" })
            <div class="col-sm-10">
                @Html.EditorFor(model => model.Content)
                @Html.ValidationMessageFor(model => model.Content)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DefaultPicUrl, new { @class = "control-label col-sm-2" })
            <div class="col-sm-10">
                <img id="imgpreview" class="thumbnail" src="" />
                @Html.HiddenFor(model => model.DefaultPicUrl)
                <a id="btn_picselect" class="easyui-linkbutton">选择…</a>
                @Html.ValidationMessageFor(model => model.DefaultPicUrl)
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}
